package nl.windgazer.arachne.pages;

import javax.servlet.http.HttpServletRequest;

import nl.windgazer.arachne.components.yql.YQLGeoIPComparisonMap;
import nl.windgazer.arachne.components.yql.YQLIPComparisonMap;
import nl.windgazer.arachne.components.yql.YQLIPLocationMap;

import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.corelib.components.TextField;
import org.apache.tapestry5.ioc.annotations.Inject;

public class IPTest {

	//Injects and Persists

	@Inject
	private HttpServletRequest _request;

	//Properties and Parameters

	@Persist
	@Property(read=true,write=true)
	private String _ipaddresses;

	@Property(read=true,write=true)
	private String _localIP;

	//Components

	@SuppressWarnings("unused")
	@Component(id = "ipForm", parameters = {})
	private Form _ipFormComponent;

	@SuppressWarnings("unused")
	@Component(id = "ipaddresses", parameters = {"value=ipaddresses"})
	private TextField _ipaddressesComponent;

	@SuppressWarnings("unused")
	@Component(id = "ipImg", parameters = {"ip=ipaddresses"})
	private YQLIPLocationMap _ipImgComponent;

	@SuppressWarnings("unused")
	@Component(id = "ipImgCluster", parameters = {"ip=ipaddresses"})
	private YQLIPComparisonMap _ipImgClusterComponent;

	@SuppressWarnings("unused")
	@Component(id = "ipImgLocation", parameters = {"ip=localIP", "baseSize=tiny", "bundleSize=mid", "width=literal:400", "height=literal:400"})
	private YQLIPComparisonMap _ipImgLocationComponent;

	@SuppressWarnings("unused")
	@Component(id = "ipImgLocation2", parameters = {"ip=localIP", "baseSize=tiny", "bundleSize=mid", "width=literal:400", "height=literal:400"})
	private YQLGeoIPComparisonMap _ipImgLocation2Component;

	//Events

	void onActivate(String ips) {
		_ipaddresses = ips;
	}

	void onActivate() {
		_localIP = _request.getRemoteHost();
		System.out.println("************* " + _localIP);
	}
	
	Object[] onPassivate() {
		return new Object[]{_ipaddresses};
	}

	//Other (check for business-logic, it should not remain here)

}
